package com.iot.service;

import com.iot.dto.DeviceRegisterDTO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.iot.entity.DeviceInfo;
import com.iot.repository.DeviceInfoMapper;
import org.springframework.transaction.annotation.Transactional;


@Service
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class DeviceInfoServiceImpl extends ServiceImpl<DeviceInfoMapper, DeviceInfo> implements DeviceInfoService {

    private final DeviceInfoMapper deviceInfoMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Long register(DeviceRegisterDTO dto) {
        DeviceInfo deviceInfo = new DeviceInfo();
        BeanUtils.copyProperties(dto, deviceInfo);
        deviceInfo.setId(null);
        deviceInfoMapper.insert(deviceInfo);
        return deviceInfo.getId();
    }
}
